public string GetCopyright(string ReturnObjectName)
{
    string str="// My methods here.\n";
        str+="//-----------------------------------------------------------------------\n";
        str+="// <Copyright file="+ReturnObjectName+" company=DHPD>\n";
        str+="// Copyright (c) DHPD Corporation (http://dhpd.edu.vn). All rights reserved.\n";
        str+="// </copyright>\n";
        str+="// <author>HP</author>\n";
        str+="//-----------------------------------------------------------------------\n";
    return str;
}

public string ReturnDattName()
{
	string stable ="dat"+ SourceTable.Name.ToString();
	return stable;
}
public string ReturnObjectName()
{
	string stable =SourceTable.Name.ToString();
	return stable;
}
public string ReturnBustName()
{
	string stable ="bus"+ SourceTable.Name.ToString();
	return stable;
}
public string ReturnEnttName()
{
	string stable ="ent"+ SourceTable.Name.ToString();
	return stable;
}
public string ReturnEntBienNameObject()
{
    int count = 0;
    string stable="";
    string s=SourceTable.Name.ToString();
    for (int i = 0; i < s.Length; i++)
    {
        if (char.IsUpper(s[i]))
        {
            stable+=s.Substring(i,1);
            count++;
        }
    }
    if(count==0){
        return "ent"+ SourceTable.Name.ToString();
    }
	return "ent"+ stable.Trim();
}
public string ReturnBusBienNameObject()
{
    int count = 0;
    string stable="";
    string s=SourceTable.Name.ToString();
    for (int i = 0; i < s.Length; i++)
    {
        if (char.IsUpper(s[i]))
        {
            stable+=s.Substring(i,1);
            count++;
        }
    }
    if(count==0){
        return "bus"+ SourceTable.Name.ToString();
    }
	return "bus"+ stable.Trim();
}
public string ReturnDatBienNameObject()
{
    int count = 0;
    string stable="";
    string s=SourceTable.Name.ToString();
    for (int i = 0; i < s.Length; i++)
    {
        if (char.IsUpper(s[i]))
        {
            stable+=s.Substring(i,1);
            count++;
        }
    }
    if(count==0){
        return "dat"+ SourceTable.Name.ToString();
    }
	return "dat"+ stable.Trim();
}
public int getCountColoumn()
{
    return SourceTable.Columns.Count;
}
public string getNameColoumnKey()
{
    foreach (ColumnSchema col in SourceTable.Columns)
    {
        if(col.IsPrimaryKeyMember)
        {
            return col.Name;
        }
    }
    return SourceTable.Columns[0].Name;
}
public string getSQLParameter()
{
    string sqlqa="";
    int i=0;
    foreach (ColumnSchema col in SourceTable.Columns)
    {
        sqlqa+="cmd.Parameters.AddWithValue(\""+col.Name+"\", "+ReturnEntBienNameObject()+"."+col.Name+");";
         sqlqa+="\n\t\t";
    }
    return sqlqa;
}
public string getInfo()
{
    string info="";
     foreach (ColumnSchema col in SourceTable.Columns)
     {
         info+= ReturnEntBienNameObject()+"."+col.Name+" = "+GetConvertTo("dr[\""+col.Name+"\"].ToString()",col)+";\n\t\t\t";
     }  
     return info;
}
public string GetDotNetType(ColumnSchema col)
{
	if (col.DataType ==  DbType.Guid)
	{
		return "Guid";
	}
	
	if (col.NativeType == "smalldatetime" || col.NativeType == "date" || col.NativeType == "datetime" || col.NativeType == "datetime2")
	{
		return "DateTime";
	}
	
	if (col.NativeType == "bigint")
	{
		return "long";
	}
	
	if (col.NativeType == "bit")
	{
		return "bool";
	}
	
	if (col.NativeType == "decimal")
	{
		return "decimal";
	}
	
	if (col.NativeType == "float")
	{
		return "decimal";
	}
	
	if (col.NativeType == "int")
	{
		return "int";
	}
	
	if (col.NativeType == "smallint")
	{
		return "short";
	}
	
	if (col.NativeType == "tinyint")
	{
		return "byte";
	}
	
	return "string";
}	

//Return value type
public string ReturnValueType(ColumnSchema col)
{
	string stemp = "";
	switch (col.DataType)
	{
		case System.Data.DbType.Guid:
			stemp = "Guid";
			break;
		case System.Data.DbType.AnsiStringFixedLength:
			stemp = "string";
			break;
		case System.Data.DbType.AnsiString:
        case System.Data.DbType.DateTime:
			stemp = "string";
			break;
		case System.Data.DbType.StringFixedLength:
			stemp = "string";
			break;
		case System.Data.DbType.Int16:
		case System.Data.DbType.Int32:
		case System.Data.DbType.Int64:
			stemp = "int";
			break;
		case System.Data.DbType.Decimal:
			stemp = "decimal";
			break;
		case System.Data.DbType.String:
			stemp = "string";
			break;
		case System.Data.DbType.Date:
			stemp = "string";
			break;
		default:
			stemp = "" + col.DataType; 
		break;
	}
	
	if (stemp!="string" && col.AllowDBNull)
	{
		//stemp+="?";
	}
	
	return stemp;
}

public void GenerateColumns()
{
	ColumnSchemaCollection GeneColumns =  new ColumnSchemaCollection(SourceTable.Columns);
	//ColumnSchemaCollection filteredColumns = FilterExcludedColumns(columns);
	int p = 0;
	for (int i = 0; i < GeneColumns.Count; i++)
	{
		
		Response.WriteLine("\t\t/// <summary>");
        Response.WriteLine("\t\t/// Gets or sets {0} field", GeneColumns[i].Name);
        Response.WriteLine("\t\t/// </summary>");
		//Response.WriteLine("\t\t[DataMember(Name = \"P{0}\")]", p);
		Response.WriteLine("\t\tpublic " + ReturnValueType(GeneColumns[i]) + " " + GeneColumns[i].Name + " { get; set; }");
		Response.WriteLine("");
		p++;
		
		if (GeneColumns[i].NativeType == "tinyint")
		{
			Response.WriteLine("\t\t/// <summary>");
        	Response.WriteLine("\t\t/// Gets or sets {0} field", GeneColumns[i].Name);
        	Response.WriteLine("\t\t/// </summary>");
			//Response.WriteLine("\t\t[DataMember(Name = \"P{0}\")]", p);
			Response.WriteLine("\t\tpublic string " + GeneColumns[i].Name + "String { get; set; }");
			Response.WriteLine("");
			p++;
		}
	}
}

public static string ToLowerFisrtChar(string input)
{
	if (string.IsNullOrEmpty(input))
	{
		return input;
	}
	
	if (input.Length == 1)
	{
		return input;
	}
	
	return string.Format("{0}{1}", input[0].ToString().ToLower(), input.Substring(1, input.Length-1));
}


public string GetSqlDBType(ColumnSchema col)
{
	if (col.DataType ==  DbType.Guid)
	{
		return "SqlDbType.UniqueIdentifier";
	}
	
	if (col.NativeType == "smalldatetime")
	{
		return "SqlDbType.SmallDateTime";
	}
	
	if (col.NativeType == "date" || col.NativeType == "datetime" || col.NativeType == "datetime2")
	{
		return "SqlDbType.DateTime";
	}
	
	if (col.NativeType == "bigint")
	{
		return "SqlDbType.BigInt";
	}
	
	if (col.NativeType == "bit")
	{
		return "SqlDbType.Bit";
	}
	
	if (col.NativeType == "decimal")
	{
		return "SqlDbType.Decimal";
	}
	
	if (col.NativeType == "float")
	{
		return "SqlDbType.Float";
	}
	
	if (col.NativeType == "int")
	{
		return "SqlDbType.Int";
	}
	
	if (col.NativeType == "smallint")
	{
		return "SqlDbType.SmallInt";
	}
	
	if (col.NativeType == "tinyint")
	{
		return "SqlDbType.TinyInt";
	}
	
	if (col.NativeType == "char")
	{
		return "SqlDbType.Char";
	}
	
	if (col.NativeType == "ntext")
	{
		return "SqlDbType.NText";
	}
	
	if (col.NativeType == "nvarchar")
	{
		return "SqlDbType.NVarChar";
	}
	
	if (col.NativeType == "text")
	{
		return "SqlDbType.Text";
	}
	
	if (col.NativeType == "varchar")
	{
		return "SqlDbType.VarChar";
	}
	
	return "";
}	


public string GetConvertTo(string inputParam, ColumnSchema col)
{
	if (col.DataType ==  DbType.Guid)
	{
		return string.Format("new Guid({0})", inputParam);
	}
	
	if (col.NativeType == "smalldatetime" || col.NativeType == "date" || col.NativeType == "datetime" || col.NativeType == "datetime2")
	{
		//return string.Format("Convert.ToDateTime({0})", inputParam);
	}
	
	if (col.NativeType == "bigint")
	{
		return string.Format("Convert.ToInt64({0})", inputParam);
	}
	
	if (col.NativeType == "bit")
	{
		return string.Format("Convert.ToBoolean({0})", inputParam);
	}
	
	if (col.NativeType == "decimal")
	{
		return string.Format("Convert.ToDecimal({0})", inputParam);
	}
	
	if (col.NativeType == "float")
	{
		return string.Format("Convert.ToDecimal({0})", inputParam);
	}
	
	if (col.NativeType == "int")
	{
		return string.Format("Convert.ToInt32({0})", inputParam);
	}
	
	if (col.NativeType == "smallint")
	{
		return string.Format("Convert.ToInt16({0})", inputParam);
	}
	
	if (col.NativeType == "tinyint")
	{
		return string.Format("Convert.ToByte({0})", inputParam);
	}
	
	return inputParam;
}

public string GetToStringValue(ColumnSchema col)
{
    if (col.DataType ==  DbType.Guid)
    {
        return ".ToString()";
    } else if (col.DataType ==  DbType.Guid || 
        col.NativeType == "smalldatetime" || col.NativeType == "date" || col.NativeType == "datetime" || col.NativeType == "datetime2"
        || col.NativeType == "bit")
	{
		return string.Empty;
	}
	else if (col.NativeType == "bigint" || col.NativeType == "float" || col.NativeType == "int"
        || col.NativeType == "int" || col.NativeType == "smallint" || col.NativeType == "tinyint")
	{
		return ".ToString(\"n0\")";
	}
    else if (col.NativeType == "decimal")
	{
		return string.Format(".ToString(\"n{0}\")", col.Scale);
	}
	
	return string.Empty;
}


public string GetControlName(ColumnSchema col)
{
	if (col.NativeType == "smalldatetime" || col.NativeType == "date" || col.NativeType == "datetime" || col.NativeType == "datetime2")
	{
		return string.Format("{0}Picker", ToLowerFisrtChar(col.Name));
	}
	else if (col.NativeType == "bit")
	{
		return string.Format("{0}CheckBox", ToLowerFisrtChar(col.Name));
	}
    else if (col.NativeType == "tinyint")
    {
        return string.Format("{0}Drop", ToLowerFisrtChar(col.Name));
    }
	else
	{
		return string.Format("{0}TextBox", ToLowerFisrtChar(col.Name));
	}
}

public string GetControlType(ColumnSchema col)
{
	if (col.NativeType == "smalldatetime" || col.NativeType == "date" || col.NativeType == "datetime" || col.NativeType == "datetime2")
	{
		return "Goline.Common.UI.NullableDateTimePicker";
	}
	else if (col.NativeType == "bit")
	{
		return "System.Windows.Forms.CheckBox";
	}
	else if (col.NativeType == "bigint" || col.NativeType == "float" || col.NativeType == "int"
        || col.NativeType == "int" || col.NativeType == "smallint" || col.NativeType == "decimal")
	{
		return "Goline.Common.UI.NumericTextBox";
	}
    else if (col.NativeType == "tinyint")
    {
        return "Goline.Common.UI.GolineComboBox";
    }
    else
	{
		return "System.Windows.Forms.TextBox";
	}
}

public string GetExtModelFieldType(ColumnSchema col)
{
    if (col.DataType ==  DbType.Guid)
    {
        return "Auto";
    }
	else if (col.NativeType == "smalldatetime" || col.NativeType == "date" || col.NativeType == "datetime" || col.NativeType == "datetime2")
	{
		return "Date";
	}
	else if (col.NativeType == "bigint")
	{
		return "Int";
	}
	else if (col.NativeType == "bit")
	{
		return "Boolean";
	}
	else if (col.NativeType == "decimal")
	{
		return "Float";
	}
	else if (col.NativeType == "float")
	{
		return "Float";
	}
	else if (col.NativeType == "int")
	{
		return "Int";
	}
	else if (col.NativeType == "smallint")
	{
		return "Int";
	}
	else if (col.NativeType == "tinyint")
	{
		return "Int";
	}
    else if (col.NativeType == "char" || col.NativeType == "ntext" || col.NativeType == "nvarchar" || col.NativeType == "text" || col.NativeType == "varchar")
    {
        return "String";
    }
	else return "Auto";
    return"";
}

